package com.cyx.controller;

import com.cyx.pojo.*;
import com.cyx.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    /**
     * 分页查询
     */
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {
        log.info("班级分页查询，参数：{}", clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }
    /**
     *  新增班级
     */
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        log.info("新增班级,参数：{}",clazz);
        clazzService.add(clazz);
        return Result.success();
    }
    /**
     *  删除班级
     */
    @DeleteMapping("{id}")
    public Result deleteClazzById(@PathVariable Integer id){
        log.info("删除班级，id：{}", id);
        clazzService.deleteClazzById(id);
        return Result.success();
    }
    /**
     * 根据ID查询班级
     */
    @GetMapping("{id}")
    public Result getInfoById(@PathVariable Integer id){
        log.info("查询班级，id：{}", id);
        Clazz clazz = clazzService.getInfoById(id);
        return Result.success(clazz);
    }
    /**
     *  修改班级
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级，参数：{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }
    /**
     *  查询所有班级
     */
    @GetMapping("/list")
    public Result list(){
        log.info("查询所有班级");
        List<Clazz> clazzList = clazzService.findAll();
        return Result.success(clazzList);
    }

}
